<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>职位管理</title>  
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
    <div class="list-row">
        <div class="list-title-1-1">
            职位
        </div>
        <div class="list-title-1-2">
            所在城市
        </div>
        <div class="list-title-1-3">
            发布时间
        </div>
    </div>
    <div id="row-data" style="background-color:#e5e5e5;">
    <c:choose>
    	<c:when test="${not empty jobList}">
	    	<c:forEach items="${jobList}" var="jd">
	        <div class="position" data-position-id="${jd.id}">
	            <div class="list-row">
	                <div class="list-position-1-1">
	                ${jd.name}
	                </div>
	                <div class="list-position-1-2">
	               		<c:forEach items="${cities}" var="city">
							<c:choose>
								<c:when test="${jd.cityId == city.id }">
				           		 ${city.name}
				       		    </c:when>
							</c:choose>
						</c:forEach>
	                </div>
	                <div class="list-position-1-3">
	                	${jd.expiredDateStr}
	                </div> 
	            </div>
	            <hr class="hrtext"/>
	        </div>
	    	</c:forEach>
    	</c:when>
    	<c:otherwise>
    		<div style="text-align:center;">
    			暂无职位信息！
    		</div>	
    	</c:otherwise>
    </c:choose>

    </div>

</div>

<!-- 测试用，正式发布关闭 
<div id="testid">
点击获取更多数据
</div>
-->
<input type="hidden" name="lastposition" id="lastjob" value="${fn:length(jobList)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});

    var datasource = { 
        moredata: function() { 
            var getUrl = '${ctx}/wechat/hunter/moreJob.do';
            var offset  = $('#lastjob').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;

            if(hasmore != "yes"){
                alert("已经没有更多数据了");
                return false;
            }
            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                       // alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) { 
            var offset = parseInt($('#lastjob').val());
            var divstring = "";
            var joblist = data.data;

            var count = joblist.length;
            offset += parseInt(count);
            $('#lastjob').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

            for (var i in joblist) {
                var jd = joblist[i];
                divstring += "<div class='position' data-position-id='"+jd.id+"'>";
                divstring += "<div class='list-row'>";
                divstring += "<div class='list-position-1-1'>";
                divstring += jd.name;
                divstring += "</div>";
                divstring += "<div class='list-position-1-2'>";
                <c:forEach items="${cities}" var="city">
				<c:choose>
					<c:when test="${jd.cityId == city.id }">
					 divstring +=city.name;
	       		    </c:when>
				</c:choose>
				</c:forEach>
                divstring += "</div>";
                divstring += "<div class='list-position-1-3'>";
                divstring += jd.expiredDateStr;
                divstring += "</div>";
                divstring += "</div>";
                divstring += "<hr class='hrtext'/>";
                divstring += "</div>";

            }

            var newdata = $(divstring);
            $('#row-data').append(newdata);
        }
    };

    $(document).ready(function() { 
	    	var l = sessionStorage.getItem('index_list');
	   	 
	    	if(null !== l && '' !== l){
	    	    $("#row-data").html(l);
	    	    $(window).scrollTop(sessionStorage.getItem('index_scroll'));
	    	    page = sessionStorage.getItem('index_page');
	    	 
	    	    sessionStorage.removeItem('index_list');
	    	    sessionStorage.removeItem('index_scroll');
	    	}else{
	    		datasource.moredata();
	    	};
       
            $(window).scroll(function() { 
                if($(window).scrollTop() == $(document).height() - $(window).height()) {
                    datasource.moredata();
                } 
            });
        
            $('.position').on('click', function() {
            	var offset  = $('#lastjob').val();
                var positionid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/hunter/toJobView.do?jobid='+positionid;
                sessionStorage.setItem('index_list',$("#row-data").html());
                sessionStorage.setItem('index_page',offset);
                sessionStorage.setItem('index_scroll',$(window).scrollTop());
                window.location.href = getUrl;
            });    
           
             wx.ready(function() {
	            wx.onMenuShareAppMessage({
	                title: 'Headoffer--专业招聘平台----推荐有奖！',  
	                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
	                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
	                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
	                type: 'link'
	            });
	
	            wx.onMenuShareTimeline({
	                title: 'Headoffer--专业招聘平台----推荐有奖！',  
	                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
	                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
	                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
	            });

            wx.showOptionMenu();
            
        });
        
    });

</script>
</body>
</html>